package com.bocai.kelala.ui.travel.set.act;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelala.App;
import com.bocai.kelala.R;
import com.bocai.kelala.base.BaseActivity;
import com.bocai.kelala.bean.PageBean;
import com.bocai.kelala.ui.travel.main.act.MainActivity;
import com.bocai.kelala.ui.travel.set.contract.AboutAppContract;
import com.bocai.kelala.ui.travel.set.module.AboutAppModule;
import com.bocai.kelala.ui.travel.set.presenter.AboutAppPresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuanfei on 2017/6/16.
 */

public class AboutAppActivity extends BaseActivity implements AboutAppContract.view {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.right_btn)
    Button rightBtn;
    @BindView(R.id.ll_delete)
    LinearLayout llDelete;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.webView)
    WebView webView;
    @Inject
    AboutAppPresenter presenter;
    int flag;

    @Override
    public int getLayoutId() {
        return R.layout.act_about_app;
    }

    @Override
    public void initPresenter() {
        App.get(this).getAppComponent().addSub(new AboutAppModule(this)).inject(this);
    }

    @Override
    public void initView() {
        flag = getIntent().getIntExtra("flag",0);
        if (flag == 0){
            initToolbar("关于客拉拉");
            initBack(imgBack,llBack);
            presenter.webViewPage("02");
        }else if (flag == 1){
            initToolbar("法律声明");
            initBack(imgBack,llBack);
            presenter.webViewPage("03");
        }
    }

    @Override
    public void getData(PageBean bean) {
//        initToolbar(bean.getTitle());
        webView.loadDataWithBaseURL("about:blank",bean.getContent(),"text/html","utf-8",null);
    }

    @Override
    public void showLoading(String title) {
        startProgressDialog(title);
    }

    @Override
    public void stopLoading() {
        stopProgressDialog();
    }

    @Override
    public void showErrorTip(String msg) {

        if (msg.equals("用户授权失败")){
            msg = "您的登录已失效，请重新登录";
            startActivity(new Intent(this,MainActivity.class).putExtra("index",1));
            finish();
        }
        showShortToast(msg);
    }
}
